<?php
/**
 * Description: customer 初始化值设置
 * Author: hezhizheng
 * Date: 2018/11/16
 * Time: 17:28
 * Created by Created by Panxsoft.
 */

namespace App\Services\Customers;

use App\Models\Customers\CustomerGroup;
use App\Services\MobileApp\AppEnv;
use App\Services\Utils\Guard;

class AppCustomer
{
    /**
     * 当前客户所属组 或 店铺默认用户组
     *
     * @var int|null
     */
    private static $customer_group_id;

    public static function initCustomerGroupId(): void
    {
        self::$customer_group_id = Guard::customer()->customer_group_id ??
            CustomerGroup::getConfigCustomerGroupId(AppEnv::storeId());
    }

    /**
     * @return int|null
     */
    public static function groupId()
    {
        if (! isset(self::$customer_group_id)) {
            self::initCustomerGroupId();
        }

        return self::$customer_group_id;
    }
}